﻿//------------------------------------------------------------------------------------------------- 
// <copyright file="ContextPluginAttribute.cs" company="Christopher Hines">
// Copyright (c) Christopher Hines. All rights reserved.
// </copyright>
// <summary>
//    Marks a decorated class as able to be plugged at runtime according to context
// </summary>
//-------------------------------------------------------------------------------------------------

namespace Copperfield
{
    using System;

    /// <summary>
    /// Marks a decorated class as able to be plugged at runtime according to context
    /// </summary>
    [AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
    public sealed class ContextPluginAttribute : Attribute
    {
        /// <summary>
        /// Gets the context provider type
        /// </summary>
        private readonly Type contextProviderType;

        /// <summary>
        /// Gets the plugin type
        /// </summary>
        private readonly Type pluginType;

        /// <summary>
        /// Gets the context type
        /// </summary>
        private readonly Type contextType;

        /// <summary>
        /// Initializes a new instance of the ContextPluginAttribute class
        /// </summary>
        /// <param name="contextType">
        /// The type of context for the plugin type
        /// </param>
        public ContextPluginAttribute(Type contextType)
        {
            this.contextProviderType = TypeUtility.GetTypeOfContextManager(contextType);
            this.contextType = contextType;
        }

        /// <summary>
        /// Initializes a new instance of the ContextPluginAttribute class
        /// </summary>
        /// <param name="contextType">
        /// The type of context for the plugin type
        /// </param>
        /// <param name="pluginType">
        /// The type of plugin
        /// </param>
        public ContextPluginAttribute(Type contextType, Type pluginType)
        {
            this.contextProviderType = TypeUtility.GetTypeOfContextManager(contextType);
            this.contextType = contextType;
            this.pluginType = pluginType;
        }

        /// <summary>
        /// Gets the context type
        /// </summary>
        public Type ContextType
        {
            get { return this.contextType; }
        }

        /// <summary>
        /// Gets the plugin type
        /// </summary>
        public Type PluginType
        {
            get { return this.pluginType; }
        }

        /// <summary>
        /// Gets the context provider type
        /// </summary>
        /// <returns>The context provider type</returns>
        public Type ContextProviderType()
        {
            return this.contextProviderType;
        }
    }
}
